﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data.MySqlClient;


namespace ctrlwct
{
    public partial class Passwdchng : Form
    {
        public string user { get; set; }
        public Passwdchng()
        {
            InitializeComponent();
            Tiempo.Enabled = true;
            Tiempo.Interval = 1;
        }
        
        private void button2_Click(object sender, EventArgs e)
        {
            
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text != textBox2.Text)
            {
                MessageBox.Show("Error, password y verificación no coinciden");
            }
            else
            {
                string passwordHashSha1 = CryptClass.Crypto.ComputeHash(textBox1.Text, "SHA1", null);
                MySqlConnection conexion = GuiLogin.Conexion.ObtenConexion();
                conexion.Open();
                if (conexion != null)
                {
                    using (MySqlCommand comando = new MySqlCommand("UPDATE Users SET Password='" + passwordHashSha1 + "' WHERE User='" + user + "'", conexion))
                        comando.ExecuteNonQuery();
                    conexion.Close();
                    this.DialogResult = DialogResult.OK;
                    this.Close();
                    
                }
            }
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            Tiempo.Stop();
            textBox3.Text = user;
        }
    }
}
